﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using DonViNganh;
using LoginModule;
namespace HDVN5.WebServices
{
    /// <summary>
    /// Summary description for DonViNganh_HeQuanTriDoanSinh
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    [System.Web.Script.Services.ScriptService]
    public class DonViNganh_HeQuanTriDoanSinh : System.Web.Services.WebService
    {

        private DonViNganhDataContext db = null;
       
        [WebMethod]
        [System.Web.Script.Services.ScriptMethod(UseHttpGet = false, ResponseFormat = System.Web.Script.Services.ResponseFormat.Json)]
        public string nhapNgayDangNhapLanDauTien(string taikhoanmoi,string tenTaiKhoanDangNhap,string matkhau,string matkhaucu)
        {
            try
            {
                string mahoa = LoginModule.Utilites.Encrypt(matkhaucu, true, tenTaiKhoanDangNhap);
                LoginModule.AccountModuleDataContext acc1 = new AccountModuleDataContext();
                LoginModule.DANGKYSUDUNG dangky = acc1.DANGKYSUDUNGs.Single(p => p.TENTAIKHOAN.Trim().ToUpper() == tenTaiKhoanDangNhap.Trim().ToUpper() && p.MATKHAU == mahoa);

                if (dangky != null)
                {

                    dangky.NGAYDANGNHAPLANDAU = DateTime.Now.Date;
                    dangky.MATKHAU = LoginModule.Utilites.Encrypt(matkhau, true, taikhoanmoi);
                    dangky.TENTAIKHOAN = taikhoanmoi;
                    dangky.NGAYSUA = DateTime.Now.Date;
                    acc1.SubmitChanges();
                    return "1";
                }
                else
                {
                    return "-1";
                }
            }
            catch (Exception ex)
            {
                return "0";
                throw new Exception(ex.Message);
                
            }
        }
 
    }
}
